package scau.erps.view.system.teacher;import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import javax.swing.table.AbstractTableModel;

import scau.erps.entity.SystemOrder;

/** 

/**
 * 系统订单表格数据模型
 * @author DCJ
 *
 */
public class OrderListModel extends AbstractTableModel {
	private static final long serialVersionUID = 1L;	
		private String[] title = {"序号","年份","产品","市场","数量","交货期","账期","价格","ISO"};
		private Object[][] data= null;
		private List<SystemOrder> list;
		public OrderListModel(List<SystemOrder> list){	
			this.list=list;
			data =  new Object[list.size()][title.length];
			Iterator<SystemOrder> iter = list.iterator();
			for (int i = 0; i < list.size(); i++) {
				SystemOrder systemOrder = iter.next();
				data[i][0] = systemOrder.getId();
				data[i][1] = systemOrder.getYear();	
				data[i][2] = systemOrder.getProduct();
				data[i][3] = systemOrder.getMarket();
				data[i][4] = systemOrder.getQuantity();
				data[i][5] = systemOrder.getDeliver();
				data[i][6] = systemOrder.getQuarter();
				data[i][7] = systemOrder.getPrice();
				data[i][8] = systemOrder.getIso();
			}	
	}

	@Override
	public int getRowCount() {
		return this.data.length; //行数
	}

	@Override
	public int getColumnCount() {
		return this.title.length; //列数
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return  data[rowIndex][columnIndex];  //取表格单元格值
	}
	public String getColumnName(int columnIndex) {
        return title[columnIndex];  //显示标题
    }
	public void showAvailableOrder(boolean ISO9000,boolean ISO14000,boolean district,boolean domestic,boolean asia,boolean internation,boolean crystal,boolean ruby,boolean sapphire){
	    List<SystemOrder> newlist=new ArrayList<SystemOrder>();
	    for (int i = 0; i < data.length; i++) {
			String product=data[i][2].toString();
			String market=data[i][3].toString();
			String ISO=null;
			if (data[i][8]!=null)
			 ISO=data[i][8].toString();
			if ((product.equals("Crystal") && crystal==false)||
					(product.equals("Ruby") && ruby==false)||
					(product.equals("Sapphire") && sapphire==false)||
					("ISO9000".equals(ISO)  && ISO9000==false)||
					("ISO14000".equals(ISO)  && ISO14000==false)||
					(market.equals("区域")  &&  district==false)||
					(market.equals("国内") && domestic==false)||
					(market.equals("亚洲") && asia==false)||
					(market.equals("国际") && internation==false)) continue;
			newlist.add(list.get(i));
		}
		data =  new Object[newlist.size()][title.length];
		Iterator<SystemOrder> iter = newlist.iterator();
		for (int i = 0; i < newlist.size(); i++) {
			SystemOrder systemOrder = iter.next();
			data[i][0] = systemOrder.getId();
			data[i][1] = systemOrder.getYear();	
			data[i][2] = systemOrder.getProduct();
			data[i][3] = systemOrder.getMarket();
			data[i][4] = systemOrder.getQuantity();
			data[i][5] = systemOrder.getDeliver();
			data[i][6] = systemOrder.getQuarter();
			data[i][7] = systemOrder.getPrice();
			data[i][8] = systemOrder.getIso();
		}	
       this.fireTableDataChanged();
	}

}
